package com.uuah.server.exception.channel;

import com.uuah.config.i18n.Message;
import com.uuah.server.api.IUuahMessage;
import com.uuah.server.api.endpoint.IUuahEndpoint;
import com.uuah.server.config.i18n.ServerMessages;
import com.uuah.server.exception.MessagingException;

/**
 *
 * TODO comment ...
 *
 * <p>
 * update record:updator，update time，update content and version
 * </p>
 *
 * @author <a href="jonny_quan@hotmail.com">jonny</a>
 * @date 2009 2009-3-27 下午01:38:46
 * @version 1.0.0
 */
public class RoutingException extends MessagingException {
	private static final long serialVersionUID = 2478458847072048645L;

	protected final transient IUuahEndpoint endpoint;

	public RoutingException(IUuahMessage message, IUuahEndpoint endpoint) {
		super(generateMessage(null, endpoint), message);
		this.endpoint = endpoint;
	}

	public RoutingException(IUuahMessage umoMessage, IUuahEndpoint endpoint,
			Throwable cause) {
		super(generateMessage(null, endpoint), umoMessage, cause);
		this.endpoint = endpoint;
	}

	public RoutingException(Message message, IUuahMessage umoMessage,
			IUuahEndpoint endpoint) {
		super(generateMessage(message, endpoint), umoMessage);
		this.endpoint = endpoint;
	}

	public RoutingException(Message message, IUuahMessage umoMessage,
			IUuahEndpoint endpoint, Throwable cause) {
		super(generateMessage(message, endpoint), umoMessage, cause);
		this.endpoint = endpoint;
	}

	public IUuahEndpoint getEndpoint() {
		return endpoint;
	}

	private static Message generateMessage(Message message,
			IUuahEndpoint endpoint) {
		Message m = ServerMessages.failedToRouterViaEndpoint(endpoint);
		if (message != null) {
			message.setNextMessage(m);
			return message;
		} else {
			return m;
		}
	}
}
